const { updataproduct, createpro, getproductinfo } = require('../../service/shopper/product')
module.exports = {
    async xiajia(ctx, next) {
        const { id, status } = ctx.request.body
        const result = await updataproduct({ id }, { status })
        if (result[0]) {
            return ctx.body = {
                code: 200,
                msg: status !== 3 ? '上架成功' : '下架成功'
            }
        }
        return ctx.body = {
            code: 0,
            msg: status !== 3 ? '上架失败' : '下架失败'
        }
    },
    async fabu(ctx, next) {
        const { title, price, lx, kw, shoperid } = JSON.parse(ctx.request.body.data)
        const img = '/img/' + ctx.request.files.img.newFilename
        console.log({ title, price: +price, lx, kw, shoperid, img })
        const rudata = await createpro({ title, price: +price, lx, kw: JSON.stringify(kw), shoperid, img })
        ctx.body = {
            code: 200,
            msg: '发布成功'
        }
    },
    async getxq(ctx, next) {
        const { id } = ctx.request.body
        const rudata = await getproductinfo({ id })
        ctx.body = {
            code: 200,
            msg: '查询成功',
            data: rudata
        }
    }
}